home *** CD-ROM | disk | FTP | other *** search
- Path: keats.ugrad.cs.ubc.ca!not-for-mail
- From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
- Newsgroups: comp.lang.c
- Subject: Re: Problem Negating an Unsigned Char
- Date: 3 Mar 1996 22:22:52 -0800
- Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
- Message-ID: <4he27sINNdel@keats.ugrad.cs.ubc.ca>
- References: <Dnnros.Lq.0.-s@hkusuc.hku.hk>
- NNTP-Posting-Host: keats.ugrad.cs.ubc.ca
-
- In article <Dnnros.Lq.0.-s@hkusuc.hku.hk>,
- Starry Hung <h8716718@hkusua.hku.hk> wrote:
- >Hi,
- >
- >The code is like that:
- >
- >unsigned char a=0x11;
- >unsigned char b=0xEE;
- >int c=0;
- >
- >void main( void ) {
-
- The declaration of main() is incorrect. It should read "int main(void)".
-
- > if( a == ~b ) {
- > c=1;
- > }
- >}
-
- exit status?
-
- >
- >The c remains unchange, while it changes to 1 if I cast the ~b to unsigned
-
- How do you know??? Your program produces no output, and fails to give an exit
- status to the operating system.
-
- >char as if( a == (unsigned char) ~b )
-
- The cast forces the integer value of ~b into an unsigned char, stripping
- high-order bits. The above will work only on machines with eight bit chars.
-
- To make it portable, you must manually mask for the lower eight bits:
-
- if (a == (~b & 0xff))
-
- --
-
-